layui.use('form', function () {
    var form = layui.form
        ,layer = layui.layer;
});
function submitcode() {
var phone=$("#phone").val();
    if (phone.length===0) {
        layer.tips("请输入手机号",'#phone',{
            tips: [1, "#0FA6D8"],
            tipsMore: !1,
            time: 2000
        });
        $("#phone").focus();
        return false;
    }
    $.ajax({
        url: basePath+"/getCode?phone=" + phone,
        contentType: "application/json;charset=UTF-8", //发送数据的格式
        type: "get",
        dataType: "json", //回调
        beforeSend: function () {
            layer.msg('稍等', {
                icon: 16
                ,shade: 0.01
            });
        },
        complete: function () {
            layer.closeAll('loading');
        },
        success: function (data) {
            if(data.status!=200){
                layer.msg(data.message, {
                    time: 1500,
                    icon: 2,
                    offset: '350px'
                });
            }else{
                layer.msg(data.message, {
                    time: 1000,
                    icon: 1,
                    offset: '350px'
                }, function () {
                   layer.msg("请稍后");
                });
            }
        }
    });
}
function submitregister() {
    var phone=$("#phone").val();
    var code=$("#code").val();
    var username=$("#username").val();
    var password=$("#password").val();
    var object = new Object(); //创建一个存放数据的对象
    object["phone"] = phone;
    object["code"] = code;
    object["password"] = password;
    object["username"] = username;
    var jsonData = JSON.stringify(object); //根据数据生成json数据
    $.ajax({
        url: basePath+"/register",
        data: jsonData,
        contentType: "application/json;charset=UTF-8", //发送数据的格式
        type: "post",
        dataType: "json", //回调
        beforeSend: function () {
            layer.msg('注册中', {
                icon: 16
                ,shade: 0.01
            });
        },
        complete: function () {
            layer.closeAll('loading');
        },
        success: function (data) {
            if(data.status!=200){
                layer.msg(data.message, {
                    time: 1500,
                    icon: 2,
                    offset: '350px'
                });
            }else{
                layer.msg(data.message, {
                    time: 1000,
                    icon: 1,
                    offset: '350px'
                }, function () {
                    location.href=basePath+"/user/login";
                });
            }
        }
    });
}